# coding=utf-8
# 代码文件：chapter3/ch3.2.7.py
import xlwings as xw
app = xw.App(visible=False, add_book=True)
wb = xw.Book()
sheet = wb.sheets.active
sheet.range('a1').value = 'Hello xlwings'   # A1单元格设置字符串

#  写入一维列表
sheet.range("a2:c2").value = [1, 2, 3]      # 为a2:c2区域赋值
wb.sheets['Sheet1'].autofit('rows')         # # 设置行高自动缩放，参数'rows'表示行高自动缩放，'rows'可以简写为'r'
wb.sheets['Sheet1'].autofit('c')            # 设置列宽自动缩放，参数'columns'表示列宽自动缩放'columns'可以简写为'c'
sheet.range("a2:a4").options(transpose=True).value = [1, 2, 3]
# 添加工作表
sheet3 = wb.sheets.add(name='Sheet3', after='Sheet1')

# 写入二维列表
sheet3.range('A1').value = [[1, 2], [3, 4]]
f = r'data/temp.xlsx'
# 保存文件
wb.save(path=f)

wb.close()
app.quit()

print('Game Over')
